package com.dq.domain.orders;

import com.dq.vo.baseVo.VO;

import com.dq.domain.orders.info.OrderInfo;
import com.dq.domain.sys.user.user.base.SysUser;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author liuhui
 * @date 2019/9/1719:48
 */

@Data
@Entity
@ApiModel("销售退货单")
public class UserOrderReturn extends Orders implements VO.ToVO{

    @ApiModelProperty("关联销售单")
    @ManyToOne
    protected Orders userOrders;

    @ApiModelProperty("退货顾客")
    @ManyToOne
    protected SysUser wxUser;

//    @ApiModelProperty("退货金额，  放到 orders 中")
//    protected BigDecimal price;

    @ApiModelProperty("退货单状态")
    protected OrderReStatus status;

    @ApiModelProperty("审批时间")
    protected Long passTime;

    @ApiModelProperty("商品件数（购买总数目）")
    protected Long payGoodsNum;
    @ApiModelProperty("商品品种数")
    protected Long cateNum;

    public enum OrderReStatus {
        waitPass("待审批"),
        pass("审核通过"),
        noPass("审批不通过"),
        end("退货完成")
        ;
        public String name;
        OrderReStatus(String name) {
            this.name = name;
        }
    }

    @Data
    @ApiModel("销售退货单视图")
    public static class Vo implements VO {
        public Long id;
        @ApiModelProperty("退货单单号")
        protected String ordersNo;
        @ApiModelProperty("关联销售单id")
        protected Long userOrdersId;
        @ApiModelProperty("关联销售单单号")
        protected String userOrdersNo;
        @ApiModelProperty("关联顾客id")
        protected Long wxUserId;
        @ApiModelProperty("关联顾客名字")
        protected String wxUserName;
        @ApiModelProperty("退货金额")
        protected BigDecimal price;

        @ApiModelProperty("退货单状态")
        public String statusEn;
        @ApiModelProperty("退货单状态")
        public String statusCn;
        @ApiModelProperty("审批时间")
        protected String passTime;

        @ApiModelProperty("关联门店id")
        protected Long orgId;
        @ApiModelProperty("关联门店名称")
        protected String orgName;

        @ApiModelProperty("创建时间(退货时间)")
        protected String createTime;
        @ApiModelProperty("备注")
        protected String remark;

        @ApiModelProperty("商品件数（购买总数目）")
        protected Long payGoodsNum;
        @ApiModelProperty("商品品种数")
        protected Long cateNum;

        @ApiModelProperty("订单详情")
        protected List<OrderInfo.OrgOrderInfoVo> orgOrderInfoVos;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.id;
        vo.ordersNo = this.ordersNo;
        vo.userOrdersId = this.getUserOrders().getId();
        vo.userOrdersNo = this.getUserOrders().getOrdersNo();
        vo.wxUserId = this.getWxUser().getId();
        vo.wxUserName = this.getWxUser().getUserRealcName();
        vo.price = this.price;
        vo.payGoodsNum = fmt(this.payGoodsNum);
        vo.cateNum = fmt(this.cateNum);

        if(this.getStatus().name.equals(OrderReStatus.end.name)) {
            vo.statusEn = UserOrderReturn.OrderReStatus.pass.toString();
            vo.statusCn = UserOrderReturn.OrderReStatus.pass.name;
        }else {
            vo.statusEn = this.getStatus().toString();
            vo.statusCn = this.getStatus().name;
        }



        vo.passTime = fmt(this.passTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);

        vo.orgId = this.getOrg() == null ? null : this.getOrg().getId();
        vo.orgName = this.getOrg() == null ? null : this.getOrg().getSimpleName();

        vo.createTime = fmt(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.remark = this.getRemark();

        return vo;
    }

}
